﻿
DECLARE @Index int
DECLARE @SplitStr varchar(2)
DECLARE @PathsStr varchar(8000)
SET @SplitStr = ','

SELECT @PathsStr = @PathsStr + [Path] 
FROM $T_TREE$
WHERE [$F_NODE_ID$] IN (1000)

DECLARE @TempStr varchar(8000)
SET @TempStr = @PathsStr
CREATE TABLE #strSplitTable(col nvarchar(100))
SET @Index = CHARINDEX(@SplitStr, @PathsStr)
WHILE(@Index <> 0)   
BEGIN   
  INSERT #strSplitTable(col) VALUES (SUBSTRING(@TempStr, 1, @Index - 1))   
  SET @TempStr = STUFF(@TempStr, 1, @Index, '')   
  SET @Index = CHARINDEX(@splitStr, @TempStr)
END
INSERT #strSplitTable(col) VALUES (@TempStr)  

SELECT * FROM $T_TREE$ 
WHERE $F_NODE_ID$ IN (
	SELECT DISTINCT col 
	FROM #strSplitTable a
	WHERE a.col <> ''
) OR $F_NODE_ID$ IN (1000)
ORDER BY $F_DEPTH$ ASC

DROP TABLE #strSplitTable